package com.apply.entity;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * @author tianp
 * 考试信息设置 apply_examinfo
 */
@Entity
@Table(name = "apply_examinfo")
@EntityListeners(AuditingEntityListener.class)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ExamInfo {
    @Id
    @GeneratedValue
    private Long id;

    private String examName;

    /**
     * 报名开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date applyStart;
    /**
     * 报名结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date applyEnd;
    /**
     * 考试开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date examStart;
    /**
     * 考试结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date examEnd;
    /**
     * 考试地点
     */
    private String examLocation;
    /**
     * 报名费用
     */
    private Double payMoney;
    /**
     * 创建人（用户名）
     */
    private String createName;
    /**
     * 考试须知
     */
    private String examNotice;
    @Transient
    private String status;
    @JsonIgnore
    @OneToMany(mappedBy = "examInfo", cascade = CascadeType.ALL)
    private Set<ApplyInfo> applyInfos;
    private int alive;
    @CreatedDate
    private Date createTime;
    @LastModifiedDate
    private Date modifiedTime;
    @Transient
    private String applyStartStr;
    @Transient
    private String applyEndStr;
    @Transient
    private String examStartStr;
    @Transient
    private String examEndStr;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getExamName() {
        return examName;
    }

    public void setExamName(String examName) {
        this.examName = examName;
    }

    public Date getApplyStart() {
        return applyStart;
    }

    public void setApplyStart(Date applyStart) {
        this.applyStart = applyStart;
    }

    public Date getApplyEnd() {
        return applyEnd;
    }

    public void setApplyEnd(Date applyEnd) {
        this.applyEnd = applyEnd;
    }

    public Date getExamStart() {
        return examStart;
    }

    public void setExamStart(Date examStart) {
        this.examStart = examStart;
    }

    public Date getExamEnd() {
        return examEnd;
    }

    public void setExamEnd(Date examEnd) {
        this.examEnd = examEnd;
    }

    public String getExamLocation() {
        return examLocation;
    }

    public void setExamLocation(String examLocation) {
        this.examLocation = examLocation;
    }

    public Double getPayMoney() {
        return payMoney;
    }

    public void setPayMoney(Double payMoney) {
        this.payMoney = payMoney;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Set<ApplyInfo> getApplyInfos() {
        return applyInfos;
    }

    public void setApplyInfos(Set<ApplyInfo> applyInfos) {
        this.applyInfos = applyInfos;
    }

    public int getAlive() {
        return alive;
    }

    public void setAlive(int alive) {
        this.alive = alive;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(Date modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public String getExamNotice() {
        return examNotice;
    }

    public void setExamNotice(String examNotice) {
        this.examNotice = examNotice;
    }

    public static ExamInfo fromJsonExam(JSONObject exam) {
        ExamInfo examInfo = new ExamInfo();
        if (null == exam) {
            return examInfo;
        }
        examInfo.setExamNotice(exam.getString("examNotice"));
        return examInfo;
    }

    public String getApplyStartStr() {
        return applyStartStr;
    }

    public void setApplyStartStr(String applyStartStr) {
        this.applyStartStr = applyStartStr;
    }

    public String getApplyEndStr() {
        return applyEndStr;
    }

    public void setApplyEndStr(String applyEndStr) {
        this.applyEndStr = applyEndStr;
    }

    public String getExamStartStr() {
        return examStartStr;
    }

    public void setExamStartStr(String examStartStr) {
        this.examStartStr = examStartStr;
    }

    public String getExamEndStr() {
        return examEndStr;
    }

    public void setExamEndStr(String examEndStr) {
        this.examEndStr = examEndStr;
    }
}
